package com.chaos.eurekaproducer.design.proxy;

import com.chaos.eurekaproducer.design.RealSubject;
import org.springframework.cglib.proxy.Enhancer;

/**
 * @author liaopeng
 * @title: CglibProxyFactory
 * @projectName eureka-producer
 * @description: TODO
 * @date 2021/7/20下午3:11
 */
public class CglibProxyFactory {

    public static RealSubject getInstance(CglibProxy proxy){
        //enhancer是一个字节码增强器
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(RealSubject.class);
        //这是回调类，强化类调用回调类中的intercept方法来执行切面逻辑。
        enhancer.setCallback(proxy);
        //返回一个添加了切面逻辑的增强类
        return (RealSubject) enhancer.create();

    }
}
